home *** CD-ROM | disk | FTP | other *** search
- /* TESTDRV
- **
- ** FILE: setup.c
- **
- ** Set up and profile parser
- **
- ** The methods here are simple. Global values are initialized
- ** to defaults and modified according to the profile information.
- ** The profile parsing is line-by-line with a simple <word><delimiter>
- ** format.
- **
- ** HISTORY:
- ** 10/01/90 Final (v1.0) -by- JYG
- ** 12/06/91 Revision - Siddhartha Roy
- */
-
- #include<stdlib.h>
- #include<string.h>
-
- #include"test.h"
-
- #define MAXLABEL 40
- #define MAXSTRING 256
-
-
- static WORD cLineNo=0;
-
- /*
- ** syntaxError() -
- */
-
- static void syntaxError(msg)
- char * msg;
- {
- printf("%s: Syntax Error Parsing Profile : line %d : %s\n",PROGNAME,cLineNo,msg);
- exit(1);
- }
-
- /* lookup() -
- **
- ** Sequential strcmpi full word lookup of all settable flags
- ** uses (static char *) szLabelTable[];
- ** returns the integer lookup index or -1 if not found
- */
-
- static short lookup ( szLabel )
- char *szLabel;
- {
- short i;
- for(i=0;i<NUM_VALS;i++) // lookup
- if (strlen(szLabelTable[i]) == strlen(szLabel) &&
- strcmpi(szLabelTable[i],szLabel) == 0)
- return i;
- return ( -1 );
- }
-
- /* getNextLine() -
- **
- ** Cook out the first useful string on a new line.
- ** Returns a pointer to the first useful character on the string
- */
-
- static char *getNextLine( pchBuf,pInFile )
- char *pchBuf;
- FILE *pInFile;
- {
- short i=0;
-
- do
- {
- cLineNo++;
- if (fgets(pchBuf,MAXSTRING,pInFile) == NULL)
- return ( NULL );
- for (i=0;isspace(pchBuf[i]);i++); // advance pointer to next char
-
- }
-
- //Skip these chars too and fetch a new line
-
- while (pchBuf[i] == ';' || pchBuf[i] == '\0');
-
- return ( pchBuf+i );
- }
-
- /*
- ** copies the next alpha string into the pchDest from pchSrc and
- ** returns a pointer to the next alpha string.
- ** pchDelim gets the value of the delimeter that ends the
- ** alpha string
- */
-
- static char *getNextString(pchDest,pchSrc,pchDelim)
- char *pchDest;
- char *pchSrc;
- char *pchDelim;
- {
- for(;isspace(*pchSrc);pchSrc++); // eliminate whitespace
- for(;isgraph(*pchSrc) && *pchSrc != ',' && *pchSrc != '=';
- *pchDest++=*pchSrc++); // copyto
- *pchDest = '\0';
- for(;isspace(*pchSrc);pchSrc++); // eliminate whitespace
- if (*pchSrc=='\0'|| *pchSrc == ';'){// end of line reached
- *pchDelim = '\n';
- return NULL;
- }
- *pchDelim=*pchSrc; // return delimeter
- return ( pchSrc+1 ); // return advanced ptr
- }
-
- /* getBool() -
- **
- ** Anticipated Boolean ([t|true] | [f|false]) is
- ** extracted and the value returned.
- ** Syntax error if none is found
- */
-
- static char getBool(pchSrc)
- char * pchSrc;
- {
-
- char * pchNext, pchDest[MAXSTRING],pchDelim;
-
- pchNext = getNextString(pchDest,pchSrc,&pchDelim);
-
- if (strlen(pchDest) == 1) {
- if (tolower(pchDest[0]) == 't')
- return TRUE;
- else if (tolower(pchDest[0]) == 'f')
- return FALSE;
- else syntaxError("Parsing BOOLEAN");
- } else if (strcmpi(pchDest,"true")==0)
- return TRUE;
- else if (strcmpi(pchDest,"false")==0)
- return FALSE;
- else syntaxError("Parsing BOOLEAN");
-
- }
-
- /*
- ** Due to the nature of the test, more levels of verbosity can
- ** be incorporated (terse,normal,verbose). Currently there are
- ** only terse and verbose modes.
- */
-
- /* setup()
- **
- ** Parses the input file and sets appropriate flags.
- */
-
- void setup(pInFile)
- FILE * pInFile;
- {
-
- extern FILE * pOutFile;
- extern FLAG fWriteMedia, fRedbook, fRaw, fPrefetch, fAudCtrl, fAudio,
- fInterleave, fEject, fUPC, fVerbose, fPrep, fSubInfo;
- extern BYTE bInterSize,bInterSkip;
- extern char szDriverName[8], *szProfileName;
- extern WORD cwAudioChan,cwHSGSectors,cwRedSectors;
- extern WORD cwErrors, cwWarnings, cwRequests;
- extern DWORD mplHSGSector[],mplRedSector[];
- extern char *szStdPath;
-
- #ifdef DEBUG
- static char szTrue[] = "TRUE";
- static char szFalse[] = "FALSE";
- #endif
-
- char szSrc[MAXSTRING],szDest[MAXSTRING],*pchNext,chDelim;
- DWORD dwMin,dwSec,dwFrame;
-
- // Presetting Defaults
- // If a flag is left UNSET, the fields of DevStat will be
- // used to set the values
-
- pOutFile = stdout;
- fWriteMedia = UNSET;
- fRedbook = UNSET;
- fRaw = UNSET;
- fPrefetch = UNSET;
- fAudCtrl = UNSET;
- fAudio = UNSET;
- fInterleave = UNSET;
- fEject = UNSET;
- fUPC = UNSET;
- fSubInfo = UNSET;
-
- cwAudioChan = 2;
- cwRedSectors= 0;
- cwHSGSectors= 0;
- bInterSize = 0;
- bInterSkip = 0;
- cwWarnings = 0;
- cwRequests = 0;
- cwErrors = 0;
-
- while ((pchNext = getNextLine(szSrc,pInFile)) != NULL) {
-
- // Point to next useful character
-
- pchNext = getNextString(szDest,szSrc,&chDelim);
- if (pchNext == NULL || chDelim != '=')
- syntaxError(szIllChar);
- // Switch on index
- switch ( lookup(szDest) ) {
- case laDRIVERNAME:
- if (getNextString(szDriverName,pchNext,&chDelim)!=NULL)
- syntaxError(szSpurCh);
- {
- BYTE cLen = (BYTE)strlen(szDriverName);
- // Pad up the rest
- for (;cLen<8;cLen++)
- szDriverName[cLen] = ' ';
- }
-
-
- #ifdef DEBUG
- printf("Driver: '%s'\n", szDriverName);
- #endif
-
- break;
-
- case laWRITEDEVICE:
- ChkRepeat(fWriteMedia);
- fWriteMedia = getBool(pchNext);
-
- #ifdef DEBUG
- printf("Write: %s\n",fWriteMedia?szTrue:szFalse);
- #endif
- break;
- case laREDBOOK:
- ChkRepeat(fRedbook);
- fRedbook = getBool(pchNext);
- #ifdef DEBUG
- printf("Redbook: %s\n",fRedbook?szTrue:szFalse);
- #endif
- break;
- case laRAWMODE:
- ChkRepeat(fRaw);
- fRaw = getBool(pchNext);
- #ifdef DEBUG
- printf("Raw: %s\n",fRaw?szTrue:szFalse);
- #endif
- break;
- case laPREFETCH:
- ChkRepeat(fPrefetch);
- fPrefetch = getBool(pchNext);
- #ifdef DEBUG
- printf("Prefetch: %s\n",fPrefetch?szTrue:szFalse);
- #endif
- break;
- case laAUDIOCNTRL:
- ChkRepeat(fAudCtrl);
- fAudCtrl = getBool(pchNext);
- #ifdef DEBUG
- printf("AudioCtrl: %s\n",fAudCtrl?szTrue:szFalse);
- #endif
- break;
- case laAUDIOCAPABLE:
- ChkRepeat(fAudio);
- fAudio = getBool(pchNext);
- #ifdef DEBUG
- printf("Audio: %s\n",fAudio?szTrue:szFalse);
- #endif
- break;
- case laAUDIOCHANNELS:
- if (getNextString(szDest,pchNext,&chDelim) !=
- NULL)
- syntaxError(szSpurCh);
- cwAudioChan = (short)atoi(szDest);
- #ifdef DEBUG
- printf("%d Audio channels\n", cwAudioChan);
- #endif
- break;
- case laINTERLEAVE:
- ChkRepeat(fInterleave);
- fInterleave = getBool(pchNext);
- #ifdef DEBUG
- printf("Interleave: %s\n ",fInterleave?szTrue:szFalse);
- #endif
-
- break;
- case laEJECT:
- ChkRepeat(fEject);
- fEject = getBool(pchNext);
- #ifdef DEBUG
- printf("Eject: %s\n",fEject?szTrue:szFalse);
- #endif
- break;
- case laUPCCODE:
- ChkRepeat(fUPC);
- fUPC = getBool(pchNext);
- #ifdef DEBUG
- printf("UPC: %s\n",fUPC?szTrue:szFalse);
- #endif
- break;
- case laOUTPUT:
- if (getNextString(szDest,pchNext,&chDelim)
- !=NULL)
- syntaxError(szSpurCh);
-
- #ifdef DEBUG
- printf("OUTFILE: %s\n",szDest);
- #endif
- if (fPrep) {
- if ((pOutFile = fopen(szDest,"w+b"))==NULL)
- syntaxError("Couldn't open binary file");
- }
- else if ((pOutFile = fopen(szDest,"w"))==NULL)
- syntaxError("Couldn't open output file");
-
- break;
-
- case laREDSECTORS:
- do {
- pchNext = getNextString(szDest,
- pchNext,&chDelim);
- sscanf(szDest,"%U:%U:%U",&dwMin,&dwSec,
- &dwFrame);
- mplRedSector[cwRedSectors++] =
- ((0x0000ffff&dwMin)<<16)|((0x0000ffff&dwSec)<<8)|
- (0x0000ffff&dwFrame);
-
- #ifdef DEBUG
- PrintRed(mplRedSector[cwRedSectors-1]);
- putchar('\n');
- #endif
- } while ( pchNext != NULL );
- #ifdef DEBUG
- printf("%d Red Sectors\n",cwRedSectors);
- #endif
- break;
-
- case laHSGSECTORS:
-
- do {
- pchNext = getNextString(szDest,
- pchNext,&chDelim);
-
-
- sscanf(szDest,"%lx",mplHSGSector
- +cwHSGSectors);
- #ifdef DEBUG
- printf(" HSG Sector %lx\n",mplHSGSector[cwHSGSectors]);
- #endif
- cwHSGSectors++;
-
- } while ( pchNext != NULL );
- break;
- case laINTERSKIP:
- if (getNextString(szDest,pchNext,&chDelim) !=NULL)
- syntaxError(szSpurCh);
- bInterSkip = (BYTE)atoi(szDest);
- #ifdef DEBUG
- printf("%d InterleaveSkip\n", bInterSkip);
- #endif
- break;
-
- case laINTERSIZE:
- if (getNextString(szDest,pchNext,&chDelim) !=NULL)
- syntaxError(szSpurCh);
- bInterSize = (BYTE)atoi(szDest);
- #ifdef DEBUG
- printf("%d InterleaveSize\n", bInterSize);
- #endif
- break;
- case laSUBINFO:
- ChkRepeat(fSubInfo);
- fSubInfo = getBool(pchNext);
- #ifdef DEBUG
- printf("Subinfo: %s\n",fSubInfo?szTrue:szFalse);
- #endif
- break;
-
- default:
- syntaxError(szUnreck);
- }
- }
-
- // Set up defaults
-
- if (szDriverName == NULL)
- syntaxError(szNodrname);
-
- if (fWriteMedia == UNSET)
- fWriteMedia = FALSE;
- if (fRedbook == UNSET)
- fRedbook = TRUE;
- if (fRaw == UNSET)
- fRaw = TRUE;
- if (fPrefetch == UNSET)
- fPrefetch = FALSE;
- if (fAudCtrl == UNSET)
- fAudCtrl = TRUE;
- if (fAudio == UNSET)
- fAudio = TRUE;
- if (fSubInfo == UNSET)
- fSubInfo = FALSE;
-
- if (fInterleave == UNSET)
- {
- fInterleave = FALSE;
- if (bInterSkip != 0 || bInterSize !=0)
- syntaxError(szBadintlv);
- }
-
-
- if (fEject == UNSET)
- fEject = TRUE;
- if (fUPC == UNSET)
- fUPC = TRUE;
- if (fVerbose == UNSET)
- fVerbose = FALSE;
- fclose(pInFile);
-
- }
-
- // Routine to check if a keyword is repeated in profile
- // New routine added
-
- static void ChkRepeat(cdflag)
- FLAG cdflag;
- {
- if (cdflag != UNSET)
- syntaxError(szRepKey);
- }